/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Authors: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.dialogos;

//import org.grupoavatar.guiaubicua.VInicial;
import org.grupoavatar.guiaubicua.VInicial;
import org.grupoavatar.guiaubicua.auxiliares.Item;
import org.grupoavatar.guiaubicua.dialogos.POI_Locked_Points.ItemAdapter;
import org.grupoavatar.guiaubicua.entidades.ARMarker;
import org.grupoavatar.guiaubicua.mix.Marker;
import org.grupoavatar.guiaubicua.punto.Comentarios;
import org.grupoavatar.guiaubicua.punto.MasterActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
//import android.location.Location;
import android.net.Uri;
import android.widget.ListAdapter;
import android.widget.Toast;

public class POI_Locked_Actions extends AlertDialog.Builder {
	//public static POI_Locked_Actions poiLockedActions = null;
	public static Activity mActivity;

	public POI_Locked_Actions(final Context context, final Marker puntoTemp, Activity actividad/*,final MixContext ctx,final MixState state*/) {		
		super(context);
		//poiLockedActions = this;
		mActivity = actividad;
		this.setTitle("Acciones");	
		final ARMarker punto = (ARMarker) puntoTemp;
		//final CharSequence[] items = punto.getAcciones();
		final Item[] items = punto.getAcciones();
		ListAdapter adapter = new ItemAdapter( context, items );
		
		
		
		this.setSingleChoiceItems(adapter, -1, new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int item) {
					switch(item) {
						case 0:	//como llegar
	//						Location location = VInicial.getCurrentLocation(); 	        	  
	//		                double latitude = location.getLatitude();
	//		                double longitude = location.getLongitude();
	//		                Intent intent = new Intent(Intent.ACTION_VIEW, 
	//		                                 Uri.parse("http://maps.google.com/maps?saddr=" + latitude + "," + longitude +
	//		                                 //Uri.parse("http://maps.google.com/maps?saddr=Current%20Location"+
	//		                                 "&daddr=" + punto.getLatitude() + "," + punto.getLongitude() + "&dirflg=w"));
	//		                             intent.setComponent(new ComponentName("com.google.android.apps.maps", 
	//		                                 "com.google.android.maps.MapsActivity"));	      
							Intent intent = new Intent(Intent.ACTION_VIEW, 
		                            Uri.parse("http://maps.google.com/maps?saddr="/* + latitude + "," + longitude*/ +
		                            "&daddr=" + punto.getLatitude() + "," + punto.getLongitude() + "&dirflg=w"));
		                        intent.setComponent(new ComponentName("com.google.android.apps.maps", 
		                            "com.google.android.maps.MapsActivity"));
		                        if (mActivity != null) 
		    	                	mActivity.startActivity(intent); 
			                break;
						case 1: //puntos obstruidos
							if (punto.getObstruidos().size()>0) {
			 	        		new POI_Locked_Points(context,punto,mActivity);
			 	        	}
			 	        	else {
				 	        	int duration = Toast.LENGTH_SHORT;
				 	        	String no_puntos_superpuestos = "No hay puntos obstruidos"; 	        		 
				 	        	Toast toast = Toast.makeText(context,no_puntos_superpuestos , duration);
			 	  	    	 	toast.show(); 	  	    	   	 
			 	        	}
							break;
						case 2:
							if (mActivity != null) {
								Intent share = new Intent(Intent.ACTION_SEND);
								share.setType("text/plain");
								share.putExtra(Intent.EXTRA_TEXT,punto.textoCompartir() );
								mActivity.startActivity(Intent.createChooser(share, "Compartir vía"));
							}
							break;
						case 3:
							if (mActivity != null) {
								MasterActivity._poi = (ARMarker)punto;
		       					MasterActivity._markerListTemporal = VInicial.dataView.getDataHandler().getMarkerList();
		       					MasterActivity._bpoi = null;
		       					MasterActivity._poiHijoAnterior = null;								
		       					mActivity.startActivity(new Intent(VInicial.getContext(), Comentarios.class));
							}
							break;
					}
 	        	}										
		});
		AlertDialog alert = create();
  	  	alert.show();
		/*
		this.setItems(items, new DialogInterface.OnClickListener() {
 	       public void onClick(DialogInterface dialog, int item) {
 	    	   //esto esta hardcodeado xq siempre va a exsitir esta accion. 	    	   
 	           if (item == 0) { 	        	  
 	        	  Location location = VInicial.getCurrentLocation(); 	        	  
                  double latitude = location.getLatitude();
                  double longitude = location.getLongitude();
                  Intent intent = new Intent(Intent.ACTION_VIEW, 
                                   Uri.parse("http://maps.google.com/maps?saddr=" + latitude + "," + longitude +
                                   //Uri.parse("http://maps.google.com/maps?saddr=Current%20Location"+
                                   "&daddr=" + punto.getLatitude() + "," + punto.getLongitude() + "&dirflg=w"));
                               intent.setComponent(new ComponentName("com.google.android.apps.maps", 
                                   "com.google.android.maps.MapsActivity"));
                  if (mActivity != null) 
                  mActivity.startActivity(intent);   
 	           }
 	          if (item == 1) { 	        	   	        	   
 	        	  if (punto.getObstruidos().size()>0) {
 	        		  POI_Locked_Points builder = new POI_Locked_Points(context,punto,mActivity);
 	        	  }
 	        	  else {
 	        		 int duration = Toast.LENGTH_SHORT;
 	        		 String no_puntos_superpuestos = "No hay puntos obstruidos"; 	        		 
 	        		 Toast toast = Toast.makeText(context,no_puntos_superpuestos , duration);
 	  	    	   	 toast.show(); 	  	    	   	 
 	        	  }
 	           }
 	       }
 	   });
		 */
	}
	
	
}
